/*
The MIT License (MIT)

Copyright (c) 2013 Mike Dapiran, Brian May, Richard Pospesel, and Bert Wierenga

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software 
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#pragma once
#include <xmmintrin.h>
#include "../Math/MathConfig.h"

namespace Hogshead
{
	namespace Common
	{
		class HMatrix4x4;
		/**
		* Vector3 class; This is considered a primitive data type in the engine. This class is a Cartesian 3-dimensional vector. The scaler components
		* are labelled x, y, and z. A large number of operators are defined for convenience. This class uses intrinsics for optimization.
		*
		* NOTE: data is stored { w, z, y, x } when viewing in IDE for debugging.
		* @author Bert Wierenga
		*
		* @see HMatrix4x4
		*/
		class __declspec( align( 16 ) ) HVector3
		{
		public:
			/**
			* Creates a zero vector.
			*/
			HVector3(void);
			~HVector3(void);

			/**
			* Construct from x,y,z floating point values
			*/
			HVector3(hfloat32 x, hfloat32 y, hfloat32 z);

			/**
			* This contructor will create a HVector3 from another HVector3.
			*
			* @param source The HVector3 to copy from.
			*/
			HVector3(const HVector3& source);

			/**
			* This constructor will create a HVector3 from a __m128 variable.
			*
			* @param source The __m128 to copy from. Assumes data is stored x,y,z,w/e.
			*/
			HVector3(const __m128& source);

			/**
			* This will copy to 'this' from 'other'.
			*
			* @param other The HVector3 to copy from.
			*
			* @return Returns *this for chaining.
			*/
			HVector3& operator=(const HVector3& other);

			/**
			* This will copy to 'this' from 'source'.
			*
			* @param source The __m128 to copy from. Assumes data is stored x,y,z,w/e.
			*
			* @return Returns *this for chaining.
			*/
			HVector3& operator=(const __m128& source);

			/**
			* This will multiply all of the components of the HVector3 by a float returned in
			* a HVector3 instance.
			*/
			HVector3 operator*(hfloat32 scalar);

			/**
			* This will multiply all of the components of the HVector3 by a float returned in
			* a HVector3 instance.
			*/
			friend HVector3 operator*(hfloat32 scalar, HVector3& vector);

			/**
			* This will do piecewise multiplication on the the HVector3's and return and instance
			* with the data.
			*/
			HVector3 operator*(const HVector3& other);

			/**
			* This will return a constant reference to the data stored in this HVector3.
			*/
			__forceinline operator const __m128&() const;

			/**
			* This will multiply all of the components of this HVector3 by a float.
			*
			* @return Returns *this for chaining.
			*/
			HVector3& operator*=(hfloat32 scalar);

			/**
			* This will add one HVector3 to another and return an instance with that data.
			*/
			HVector3 operator+(const HVector3& to_add);

			/**
			* This will subtrace one HVector3 from another and return an instance with that data.
			*/
			HVector3 operator-(const HVector3& to_subtrace);

			/**
			* This will add one HVector3 to this.
			*
			* @return Returns *this for chaining.
			*/
			HVector3& operator+=(const HVector3& to_add);

			/**
			* Checks for equivalence of two HVector3's.
			*/
			bool operator==(const HVector3& other);

			/**
			* Checks for inequality of the two HVector3's.
			*/
			bool operator!=(const HVector3& other);

			
			
			/**
			* performs a dot product on the two HVector3's.
			*
			* @return Returns the dot product of the two HVector3's.
			*/
			static hfloat32 dot(const HVector3& one, const HVector3& two);

			//Constant static members
			const static HVector3& zero;
			const static HVector3& unit_x;
			const static HVector3& unit_y;
			const static HVector3& unit_z;

		private:
			/* storage for x,y,z and a spare */
			/* { spare = 0, z, y, x } */
			__m128 _data;
			friend class HMatrix4x4;
			friend class HVector4;
			friend class HQuaternion;
		};
	}
}
